package com.ruoyi.paper.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.paper.domain.ExamLib;
import com.ruoyi.paper.service.IExamLibService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 实训试题库Controller
 * 
 * @author ruoyi
 * @date 2025-04-14
 */
@Controller
@RequestMapping("/jxsx/lib")
public class ExamLibController extends BaseController
{
    private String prefix = "jxsx/lib";

    @Autowired
    private IExamLibService examLibService;

    @RequiresPermissions("jxsx:lib:view")
    @GetMapping()
    public String lib()
    {
        return prefix + "/lib";
    }

    /**
     * 查询实训试题库列表
     */
    @RequiresPermissions("jxsx:lib:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ExamLib examLib)
    {
        startPage();
        List<ExamLib> list = examLibService.selectExamLibList(examLib);
        return getDataTable(list);
    }

    /**
     * 导出实训试题库列表
     */
    @RequiresPermissions("jxsx:lib:export")
    @Log(title = "实训试题库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ExamLib examLib)
    {
        List<ExamLib> list = examLibService.selectExamLibList(examLib);
        ExcelUtil<ExamLib> util = new ExcelUtil<ExamLib>(ExamLib.class);
        return util.exportExcel(list, "实训试题库数据");
    }

    /**
     * 新增实训试题库
     */
    @RequiresPermissions("jxsx:lib:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存实训试题库
     */
    @RequiresPermissions("jxsx:lib:add")
    @Log(title = "实训试题库", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ExamLib examLib)
    {
        return toAjax(examLibService.insertExamLib(examLib));
    }

    /**
     * 修改实训试题库
     */
    @RequiresPermissions("jxsx:lib:edit")
    @GetMapping("/edit/{examLibId}")
    public String edit(@PathVariable("examLibId") String examLibId, ModelMap mmap)
    {
        ExamLib examLib = examLibService.selectExamLibByExamLibId(examLibId);
        mmap.put("examLib", examLib);
        return prefix + "/edit";
    }

    /**
     * 修改保存实训试题库
     */
    @RequiresPermissions("jxsx:lib:edit")
    @Log(title = "实训试题库", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ExamLib examLib)
    {
        return toAjax(examLibService.updateExamLib(examLib));
    }

    /**
     * 删除实训试题库
     */
    @RequiresPermissions("jxsx:lib:remove")
    @Log(title = "实训试题库", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(examLibService.deleteExamLibByExamLibIds(ids));
    }
}
